<?php

namespace App\Http\Controllers\Car;

use App\Helpers\ResponseData;
use App\Http\Controllers\Controller;
use App\Models\Car\CarCost;
use App\Models\Car\RetentionContent;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;

class RetentionController extends Controller
{
    use ResponseData;
    public function index(RetentionContent $model,Request $request) {
        $size = $request->input('size',10);
        $data = $model->paginate($size);
        return $this->success($data);
    }
    public function store(RetentionContent $model,Request $request){
        $data = $request->all();
        $model->fill($data);
        $model->save();
        return $this->success('保存成功');
    }
    public function edit(RetentionContent $model,Request $request){
        if($request->filled('order_sn')){
            $data = $model->where('order_sn',$request->order_sn)->first();
        } else {
            $data = $model->find($request->id);
        }
        return $this->success($data);
    }
    public function update(RetentionContent $model,Request $request){
        $data = $model->find($request->id);
        $data->update($request->all());
        return $this->success('修改成功');
    }
    public function destory(RetentionContent $model,Request $request){
        if($request->filled('order_sn')){
            $data = $model->where('order_sn',$request->order_sn)->first();
        } else {
            $data = $model->find($request->id);
        }
        $data->delete();
        return $this->success('删除成功');
    }
}
